﻿using LxBasic;

namespace LxCore.Samples
{
    public class FlowAroundCylinder : SampleVMBase
    {
        public FlowAroundCylinder()
        {
            this.Name = "圆柱绕流";
            this.FileName = "圆柱绕流.msh";
        }
        public override void RunCase()
        {
            ReadFile();
            LxSim.Sim.Info.ProjName = Name;
            var sim = LxSim.Sim;
            sim.Physics.TimeDiscreteType = TimeDiscreteTypes.Implicit_2nd;
            sim.Physics.TimeInterval = new ConstField.Double(2);
            var physical = LxSim.Sim.Physics.CreatePhysicalModel();
            physical.PhysicalType = PhysicalTypes.流体;

            var z = FindZone("AIR");
            ResHelper.GetCond(z).PhysicalModel = physical;

            var inlet = FindBound(z, "Y-");
            var inletCond = ResHelper.GetCond(inlet);
            inletCond.BoundType = BoundTypes.速度入口;
            inletCond.VelocityMagnitude = new ConstField.Double(0.05);

            var sym = FindBound(z, "SYMMETRY");
            var symCond = ResHelper.GetCond(sym);
            symCond.BoundType = BoundTypes.对称面;

            var outlet = FindBound(z, "Y+");
            var outletCond = ResHelper.GetCond(outlet);
            outletCond.BoundType = BoundTypes.压力出口;

            var graph = LxSim.Sim.Visuals.CreateGraph("流场");
            graph.GraphType = GraphTypes.矢量图;
            graph.ScalarType = ScalarFieldTypes.Velocity;
            graph.ScaleFactor = 0.5;
            graph.SetSelector(z.Inner, true);

            graph = LxSim.Sim.Visuals.CreateGraph("MassImbalance");
            graph.GraphType = GraphTypes.等值图;
            graph.ScalarType = ScalarFieldTypes.MassImbalance;
            graph.SetSelector(sym, true);

            graph = LxSim.Sim.Visuals.CreateGraph("Pressure");
            graph.GraphType = GraphTypes.等值图;
            graph.ScalarType = ScalarFieldTypes.Pressure;
            graph.SetSelector(sym, true);
            graph.SetSelector(inlet, true);
            graph.SetSelector(outlet, true);
            sim.Steps.IterationStep.MaxStepRule.MaxStep = 20;
            sim.Steps.TimeStep.MaxStepRule.MaxStep = 10000;
            sim.Steps.TimeStep.MaxTimeRule.MaxTime = 100;
            MultiThreads.SetThreadsCount(3);
            RunSimulation();
        }
    }
}
